//
//  MCPaySelectedLotteryHeaderView.m
//  TLYL
//
//  Created by MC on 2017/6/16.
//  Copyright © 2017年 TLYL01. All rights reserved.
//

#import "MCPaySelectedLotteryHeaderView.h"
@interface MCPaySelectedLotteryHeaderView ()
/**距024期截止：05：33：22*/
@property (nonatomic,strong)UILabel * titleLabel;
@property (nonatomic,strong)NSTimer * timer;
//@property (nonatomic,assign)NSInteger  seconds;

@end

@implementation MCPaySelectedLotteryHeaderView
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createUI];
    }
    return self;
}

-(void)createUI{
    
    self.backgroundColor=[UIColor clearColor];
    /**距024期截止：05：33：22*/
    _titleLabel =[[UILabel alloc]initWithFrame:CGRectZero];
    _titleLabel.textColor=RGB(0, 0, 0);
    _titleLabel.font=[UIFont systemFontOfSize:14];
    _titleLabel.text =@"加载中";
    _titleLabel.textAlignment=NSTextAlignmentCenter;
    [self  addSubview:_titleLabel];
    
    [self layOutConstraints];
}

+(CGFloat)computeHeight:(id)info{
    return 30;
}

-(void)setDataSource:(int)dataSource{
    _dataSource=dataSource;
//    _seconds= dataSource;
    [self SetTime];
    [self add_timer];
}


#pragma mark-添加定时器
-(void)add_timer{
    _timer = [NSTimer timerWithTimeInterval:1.0 target:self selector:@selector(timerAction) userInfo:nil repeats:YES];
    NSRunLoop *currentRunLoop = [NSRunLoop currentRunLoop];
    [currentRunLoop addTimer:_timer forMode:NSRunLoopCommonModes];
    
}

-(void)timerAction{
    if (_dataSource==0) {
        _titleLabel.text =@"距X期截止 : 00:00:00";
        [_timer invalidate];
        _timer = nil ;
        if (self.timeISZeroBlock) {
            self.timeISZeroBlock();
        }
    }else{
        _dataSource--;
        [self SetTime];
        
    }
    
}
#pragma mark-设计时间
-(void)SetTime{
    int hour   = (int)_dataSource/3600;
    int minute = (int)(_dataSource - hour*3600)/60;
    int second = (int)_dataSource%60;
    _titleLabel.text =[NSString stringWithFormat:@"距%@期截止 : %.2d:%.2d:%.2d",_IssueNumber,hour,minute,second];
    
}


-(void)layOutConstraints{
    
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(0);
        make.top.equalTo(self.mas_top).offset(0);
        make.bottom.equalTo(self.mas_bottom);
        make.right.equalTo(self.mas_right);
    }];
    
}



/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect {
 // Drawing code
 }
 */

@end













































